package com.whalehearing.tingyou.api.controller.hearing;

import com.whalehearing.tingyou.common.annotation.DataSource;
import com.whalehearing.tingyou.common.annotation.Log;
import com.whalehearing.tingyou.common.core.controller.BaseController;
import com.whalehearing.tingyou.common.core.domain.AjaxResult;
import com.whalehearing.tingyou.common.core.page.TableDataInfo;
import com.whalehearing.tingyou.common.enums.BusinessType;
import com.whalehearing.tingyou.common.enums.DataSourceType;
import com.whalehearing.tingyou.domain.HearingImg;
import com.whalehearing.tingyou.domain.HearingImgValue;
import com.whalehearing.tingyou.service.IHearingImgService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 听力图Controller
 *
 * @author zengjun-qxm
 * @date 2024-09-13
 */
@Api(tags = "Api听力图管理")
@RestController
@RequestMapping("/api/tingyou/hearingImg")
public class ApiHearingImgController extends BaseController {
    @Autowired
    private IHearingImgService hearingImgService;

//    /**
//     * 新增听力图------------
//     */
//    @ApiOperation("新增听力图")
//    @Log(title = "听力图", businessType = BusinessType.INSERT)
//    @PostMapping("/saveHearingImg")
//    public AjaxResult add(@RequestBody List<HearingImg> hearingImg) {
//        hearingImgService.saveHearingImg(hearingImg);
//        return AjaxResult.success();
//    }

    /**
     * 新增听力图
     */
    @ApiOperation("新增听力图")
    @Log(title = "听力图", businessType = BusinessType.INSERT)
    @PostMapping("/saveHearingImg")
    public AjaxResult add(@RequestBody HearingImg hearingImg) {
        System.out.println("sssss");
        boolean isSaved = hearingImgService.save(hearingImg);
        //返回主键听力图id
        if (isSaved && hearingImg.getHearingImgId() != null) {
            return AjaxResult.success(hearingImg.getHearingImgId());
        } else {
            return AjaxResult.error("插入失败");
        }

    }

    /**
     * 查询听力图列表
     */
    @ApiOperation("查询听力图列表")
    @GetMapping("/list")
    public TableDataInfo list(HearingImg hearingImg) {
        startPage();
        List<HearingImg> list = hearingImgService.selectHearingImgList(hearingImg);
        return getDataTable(list);
    }

    /**
     * 获取听力图详细信息
     */
    @ApiOperation("获取听力图详细信息")
    @GetMapping(value = "/{hearingImgId}")
    public AjaxResult getInfo(@PathVariable("hearingImgId") Long hearingImgId) {
        return success(hearingImgService.getById(hearingImgId));
    }

    /**
     * 删除听力图
     */
    @ApiOperation("删除听力图")
    @Log(title = "听力图", businessType = BusinessType.DELETE)
    @DeleteMapping("/{hearingImgIds}")
    public AjaxResult remove(@PathVariable Long[] hearingImgIds) {
        return toAjax(hearingImgService.removeByIds(Arrays.asList(hearingImgIds)));
    }
}
